<?php
namespace Test;

class ConvertDayReport extends Convert
{
    public function convert($school, $schoolId, $groupinfo, $spaceid, $classid, $class, $studentId, $studentOld)
    {
        printf("  Get old day report data.\n");
        $search = $this->connection->table('yuanbao_v1.t_day_report')->where('receiverCode', '=', $studentOld->studentCode)
            ->get();

        printf("  Convert old day report.\n");
        foreach ($search as $record) {
            $feeling = function ($feelingName) {
                switch ($feelingName) {
                    case '高兴':
                        return 1;
                    case '一般':
                        return 2;
                    case '低落':
                        return 3;
                    case '烦躁':
                        return 4;
                }
            };
            $teacherId = $this->connection->table('convert.v2_sys_user')->where('user', '=', $record->publisherCode)->pluck('id');
            if ($teacherId === null) continue;
            $this->connection->table('convert.v2_school_report_day')->insert(array(
                'space' => $spaceid,
                'school_id' => $schoolId,
                'teacher_id' => $teacherId,
                'student_id' => $studentId,
                'class_id' => $classid,
                'created_time' => strtotime($record->publishTime),
                'eat_num' => $record->eatNum,
                'nap_time' => $record->napTime,
                'drink_num' => $record->drinkNum,
                'stool_num' => $record->stoolNum,
                'other' => $record->other,
                'feeling' => $feeling($record->feeling)
            ));
        }
    }
} 